home *** CD-ROM | disk | FTP | other *** search
- unit Const1;
- { PC Plus sample Delphi program.
- Show how to declare global and local Constants }
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, StdCtrls;
-
- type
- TForm1 = class(TForm)
- ListBox1: TListBox;
- Button1: TButton;
- procedure Button1Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
-
- { Global Constants
- These aren't as 'bad' as global variables since, being constant,
- their values cannot change during program execution. So they can't
- cause the same unexpected 'side-effects' as global variables }
- const
- LOOPLIMIT = 4;
- MAG = 'PC Plus';
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- procedure TForm1.Button1Click(Sender: TObject);
- const
- ThisProc = 'TForm1.Button1Click'; { local const }
- var
- i : integer;
- begin
- With ListBox1.Items do
- begin
- for i := 1 to LOOPLIMIT do
- Add('Loop: ' + IntToStr( i ) );
- Add( 'You are reading ' + MAG );
- Add( 'Current procedure is ' + ThisProc );
- end;
- end;
-
-
-
- end.
-